<template>
	<view>
		<view style="padding: 3%;">
			<u--input
			placeholder="请输入姓名"
			border="bottom"
			@input="input"
			>
			<u-text
				text="真实姓名:"
				slot="prefix"
				margin="0 3px 0 0"
				type="tips">
			</u-text>
			</u--input>
		</view>
		<view style="margin: 3%;display: flex; padding-bottom: 1%; border-bottom: 1rpx solid #e1e1e1">
			<view style="margin-left: 2%; margin-top: 2%;font-size: 30rpx;color: #7f7f7f;">
				学校:
			</view>
			<uni-combox style="width: 80%; border: none;" :candidates="schoolNameList" placeholder="请选择院校" v-model="value" @input="getSchool()"></uni-combox>
		</view>
		<view style="padding: 3%;">
			<u--input
			type="number"
			placeholder=""
			border="bottom"
			>
			<u-text
				text="联系方式:"
				slot="prefix"
				margin="0 3px 0 0"
				type="tips">
			</u-text>
			</u--input>
		</view>
		<view style="padding: 3%;">
			<u--input
			type="number"
			placeholder=""
			border="bottom"
			>
			<u-text
				text="身份证:"
				slot="prefix"
				margin="0 3px 0 0"
				type="tips">
			</u-text>
			</u--input>
		</view>
		<view style="padding: 3%;">
			<u--input
			type="number"
			placeholder=""
			border="bottom"
			@input="inputStudentId"
			>
			<u-text
				text="学号:"
				slot="prefix"
				margin="0 3px 0 0"
				type="tips">
			</u-text>
			</u--input>
		</view>
		<button @click="sumbit()">提交</button>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
import value from '../../../uni_modules/uview-ui/components/u-text/value'
	export default {
		data() {
			return {
				toast:{
					type:'success',
					title:'成功',
					message:'提交成功',
					iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png',
					url:'/pages/user/index'
				},
				value:'',
				userSchool:{
					userId:0,
					schoolId:0,
					realName:null,
					studentId:null,
				},
				phone:null,
				schoolList:[],
				schoolNameList:[],
			}
		},
		methods: {
			showToast(params) {
				this.$refs.uToast.show({
					...params,
					complete() {
						params.url && uni.reLaunch({
							url: params.url
						})
					}
				})
			},
			inputStudentId(e){
				this.userSchool.studentId = e
			},
			input(e){
				this.userSchool.realName = e
			},
			getSchool(){
				for(let i = 0;i<this.schoolList.length;i++){
					if(this.value === this.schoolList[i].name){
						this.userSchool.schoolId = this.schoolList[i].id
						console.log(this.userSchool)
					}
				}
			},
			sumbit(){
				uni.request({
					url:'http://localhost:8090/nailCampus/school/addUserSchool',
					method:'POST',
					data:this.userSchool,
					success:res=>{
						this.showToast(this.toast)
					}
				})
			}
		},
		onLoad() {
			this.userSchool.userId = uni.getStorageSync('user').id
			uni.request({
				url:'http://localhost:8090/nailCampus/school/getSchoolList',
				method:'GET',
				success:res=>{
					this.schoolList = res.data.data
					this.schoolList.forEach(item=>{
						this.schoolNameList.push(item.name)
					})
				}
			})
		}
	}
</script>

<style lang="less" scoped>
button{
	margin-top: 10%;
	width: 60%;
	font-size: 40rpx;
	background-color: #0080ff;
	color: white;
}
button::after{
	border: none;
}
</style>
